package com.lanmei.group.weixin.controller.admin;

import java.util.Date;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.lanmei.group.weixin.model.CmsCategory;
import com.lanmei.group.weixin.utils.RequestUtil;
import com.lanmei.group.weixin.utils.ShiroUtil;
@RequiresRoles(value = {"user" },logical=Logical.OR)
public class CmsCategoryControlloer extends Controller {
	
	public void list(){
		int siteId = RequestUtil.getSiteId(getSession());
		Page<CmsCategory> page = new CmsCategory().paginatRoot(1, 10,siteId);
		setAttr("page", page);
		render("list.jsp");
	}
	public void toAdd(){
		render("add.jsp");
	}
	public void add(){
		CmsCategory cate = getModel(CmsCategory.class, "cate");
		cate.setCreateTime(new Date());
		int siteId = RequestUtil.getSiteId(getSession());
		cate.setCreateUser(ShiroUtil.getLoginName());
		cate.setSiteId(siteId);
		cate.save();
		this.redirect("/admin/cmscategory/list");
	}
	public void toEdit(){
		int catId = getParaToInt("catId");
		CmsCategory cate = CmsCategory.dao.findById(catId);
		setAttr("cate", cate);
		render("edit.jsp");
	}
	public void update(){
		CmsCategory cate = getModel(CmsCategory.class, "cate");
		cate.setUpdateTime(new Date());
		cate.setUpdateUser(ShiroUtil.getLoginName());
		cate.update();
		this.redirect("/admin/cmscategory/list");
	}
	public void delete(){
		int catId = getParaToInt("catId");
		CmsCategory cate = CmsCategory.dao.findById(catId);
		cate.delete();
		this.redirect("/admin/cmscategory/list");
	}
	public void toChildList(){
		int catId = getParaToInt("catId");
		Page<CmsCategory> page = new CmsCategory().paginatByParentId(1, 10, catId);
		setAttr("catId", catId);
		setAttr("page", page);
		render("childList.jsp");
	}
	public void toAddChild(){
		int catId = getParaToInt("catId");
		setAttr("catId", catId);
		render("addChild.jsp");
	}
}
